from nonebot import on_regex
from nonebot.typing import T_State
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message
import requests


random_joke = on_regex(pattern=r'^讲个笑话$')
random_tg = on_regex(pattern=r'^舔狗日记$')
random_wyy = on_regex(pattern=r'^悲伤$')


@random_joke.handle()
async def joke(bot: Bot, event: GroupMessageEvent, state: T_State):
    msg = await get_joke()
    # at_ = f"[CQ:at,qq={event.get_user_id()}]"
    await random_joke.send(Message(msg))


async def get_joke():
    url = 'https://api.lklblog.cn/api/qwxh.php'
    get_data = requests.get(url=url, timeout=20)
    # print(get_data)
    get_txt = get_data.text
    # print(data)
    return get_txt


@random_tg.handle()
async def tg(bot: Bot, event: GroupMessageEvent, state: T_State):
    msg = await get_tg()
    # at_ = f"[CQ:at,qq={event.get_user_id()}]"
    await random_tg.send(Message(msg))


async def get_tg():
    url = 'https://api.lklblog.cn/api/tgrj.php'
    get_data = requests.get(url=url, timeout=20)
    # print(get_data)
    get_txt = get_data.text
    # print(data)
    return get_txt


@random_wyy.handle()
async def wyy(bot: Bot, event: GroupMessageEvent, state: T_State):
    msg = await get_wyy()
    # at_ = f"[CQ:at,qq={event.get_user_id()}]"
    await random_tg.send(Message(msg))


async def get_wyy():
    url = 'https://api.lklblog.cn/api/sgyl.php'
    get_data = requests.get(url=url, timeout=20)
    # print(get_data)
    get_txt = get_data.text
    # print(data)
    return get_txt
